package week5.day32;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Author fengzihao
 * @Date 2024-05-16 19:23
 */
public class DeweightUseArrayList {
    public static void main(String[] args) {
        String str = "abcqweracb";
        String string = removeRepeat(str);
        System.out.println("string = " + string);
    }
    /**
     * 给定一个字符串, 去除这个字符串中重复的数值, 得到一个不变前后顺序的不重复字符串
     * @param str: 给定字符串
     * @return: 去除重复值的字符串
     */
    private static String removeRepeat(String str) {
        char[] charArray = str.toCharArray();
        List<Character> charList = new ArrayList<>();
        for (char c : charArray) {
            if (!charList.contains(Character.valueOf(c)))
                charList.add(Character.valueOf(c));
        }
        String result = "";
        Iterator<Character> iterator = charList.iterator();
        while (iterator.hasNext()){
            result = result + iterator.next();
        }
        return result;
    }
}

